import {
    createSlice
} from "@reduxjs/toolkit";
import {useSelector} from "react-redux";
import {getHospitalSet} from "@/api/hosp";

const hospSlice = createSlice({
    name:"hosp",
    initialState:{
        hospSetList:[]
    },
    reducers:{
        upHospSetList(state,{payload}){
            state.hospSetList = payload;
        }
    }
})
const {upHospSetList} = hospSlice.actions;
// 获取状态列表
export const getHospitalSetAsync = function(page:number,limit:number){
    return async (dispatch:any)=>{
        const result = await getHospitalSet(page,limit);
        dispatch(upHospSetList(result.data.records));
    }
}
// 导出状态
export const useSelectorHosp = ()=>useSelector((state:any)=>state.hosp);
export default hospSlice.reducer;